package com.hd.crdao.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hd.crdao.activity.ReleaseActivity;
import com.hd.crdao.wrapper.GlideImageUtils;

import java.util.ArrayList;

/**
 *
 *@author Administrator
 *@date 2017/5/27 0027
 */

public class MyViewPagerAdapter extends PagerAdapter {

    private ArrayList<String> mList = new ArrayList<>();
    private Context context;

    public MyViewPagerAdapter(ArrayList<String> list,Context mContext) {
        this.mList = list;
        this.context=mContext;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        container.removeView((View) object);


    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
        ImageView iv = new ImageView(container.getContext());
        iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
        GlideImageUtils.loadImage(mList.get(position),iv);

      iv.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              ((ReleaseActivity)context).toGetImageFromOther();
          }
      });
        container.addView(iv);
        return iv;
    }
}
